/**
 * 计算累加时间的函数
 * @param date {string} 开始时间
 * @param duration {string} 增加的时长
 * @example countDate('00:00', '0,30')
 */

export const countDate = (date, duration = '0,30') => {
	const durationArr = duration.split(',') || [];
	const dateArr = date.split(':') || [];
	// console.log('durationArr', durationArr);
	// console.log('dateArr', dateArr);
	let minuteCount = 0;
	let hourCount = 0;
	if (durationArr.length > 0) {
		if (durationArr[0].length === 1) {
			durationArr[0] = durationArr[0];
		}
		if (dateArr[1] * 1 + durationArr[1] * 1 >= 60) {
			minuteCount = ((dateArr[1] * 1 + durationArr[1] * 1) % 60) + '';
			hourCount =
				dateArr[0] * 1 +
				durationArr[0] * 1 +
				parseInt((dateArr[1] * 1 + durationArr[1] * 1) / 60) +
				'';
			// console.log(
			// 	'hourCount====>',
			// 	hourCount,
			// 	'dateArr[0] * 1',
			// 	dateArr[0] * 1,
			// 	'parseInt((dateArr[1] * 1 + durationArr[1] * 1) / 60)',
			// 	parseInt((dateArr[1] * 1 + durationArr[1] * 1) / 60)
			// );
		} else {
			minuteCount = dateArr[1] * 1 + durationArr[1] * 1 + '';
			hourCount = dateArr[0] * 1 + durationArr[0] * 1 + '';
		}
		if (hourCount >= 24) {
			hourCount = hourCount * 1 - 24;
		}
		// console.log('minuteCount-======', minuteCount, 'hourCount=====', hourCount);
	}
	return `${hourCount.length >= 2 ? hourCount : '0' + hourCount}:${
		minuteCount.length >= 2 ? minuteCount : '0' + minuteCount
	}`;
};
